import {
  Toast
} from "vant";
import cTitle from "components/title";
export default {
  data() {
    return {
      realname: '', //真实姓名
      idcardNum: '', //身份证号
      isLoadding: false,
    };
  },

  components: {
    cTitle
  },
  activated() {
    this.uploadUrl = this.fun.getRealUrl("upload.uploadPic", {});
    if (!localStorage.getItem("uid")) {
      this.$router.push(this.fun.getUrl("login"));
      return
    }
    this.initData();
  },
  computed: {

  },
  methods: {
    initData(){
      this.realname = '';
      this.idcardNum = '';
    },
    // 提交
    submit(){
      if(this.realname == ''){
        Toast('请填写真实姓名')
        return
      }
     
      if(this.idcardNum == ''){
        Toast('请填写身份证号')
        return
      }
      
      if(this.isLoadding){
        Toast('请勿重复点击')
        return
      }
      this.isLoadding = true;
        $http.get("NiuTwo.real_name", {
            uid: localStorage.getItem("uid"),
            name: this.realname,
            idcard: this.idcardNum
        }, "加载中").then((res) => {
            if (res.result == 1) {
              Toast('提交成功')
              setTimeout(()=>{
                this.isLoadding = false;
                this.$router.push(this.fun.getUrl("balance"));
              },1000)
            }else {
              Toast(res.msg)
              this.isLoadding = false;
            }
          }).catch(err => {
            Toast(err)
            this.isLoadding = false;
          });
    },
    onCopy() {
      Toast({
        message: "复制成功",
        duration: 2000
      });
    },
    /*vant图片上传*/
    onRead(e, flag) {
      console.log(flag.name, "e, flag");
      let typeUpload = flag.name; //0 授权信息 1身份证正面 2身份证反面
      Toast.loading({
        message: "上传中",
        forbidClick: true
      });
      this.stopButton = true;
      let fd = new FormData();

      if (flag === true) {
        fd.append("file", e); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      } else {
        fd.append("file", e.file); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      }
      var That = this;
      axios
        .post(this.uploadUrl, fd, {
          headers: {
            "Content-Type": "multipart/form-data"
          }
        })
        .then(response => {
          var responseData = response.data;
          console.log(responseData, "responseData");
          if (responseData.result === 1) {
            Toast.clear();
            That.paymentvoucher = responseData.data.img_url;
          } else {
            Toast(responseData.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getConfig() {
      $http.get("NiuTwo.huikuan_config", {}, "加载中").then((res) => {
        if (res.result == 1) {
          console.log(res, 'shuju_list')
          this.corporate_name = res.data.niuniu_gongsi;
          this.openingBank = res.data.niuniu_kaihu;
          this.subBranch = res.data.niuniu_zhanghao;
          this.bankAccountNumber = res.data.niuniu_zihang;

        }
      });
    },


  }
};